//
//  EventsView.m
//  LStyle
//
//  Created by Obaid Abdul Maroof on 12/20/09.
//  Copyright 2009 Vrije University. All rights reserved.
//

#import "EventsView.h"


@implementation EventsView


static id nav;
/*
 // The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	nav = self.navigationController;
	tvEvents.separatorStyle = UITableViewCellSeparatorStyleNone;
	self.createFooter;
	tcEvents = [[UITabBar alloc] initWithFrame:CGRectMake(0, 480-50, 320, 30)];
	
	[tcEvents addSubview:lblAll];
	[tcEvents addSubview:lblCity];
	[tcEvents addSubview:lblCreate];
	
	[self.view addSubview:tcEvents];
	
	[activityIndicator startAnimating];
	tvEvents.hidden = TRUE;
	
	currentLabel = lblAll;
	currentView = self.view;
		
}


- (void)viewDidAppear:(BOOL)animated{
	tvEvents.delegate = self;
	tvEvents.dataSource = self;
	
	[tvEvents reloadData];
	
	[activityIndicator stopAnimating];
	activityIndicator.hidden = TRUE;
	tvEvents.hidden = FALSE;
}


-(void) createFooter{
	UIFont *fnt = [UIFont fontWithName:@"Verdana" size: 10.0];
	lblAll = [[UILabel alloc] initWithFrame:CGRectMake(15, 5, 60, 20)];
	lblCity = [[UILabel alloc] initWithFrame:CGRectMake(90, 5, 70, 20)];
	lblCreate = [[UILabel alloc] initWithFrame:CGRectMake(180, 5, 70, 20)];
	
	
	lblAll.textAlignment = UITextAlignmentCenter;
	lblCity.textAlignment = UITextAlignmentCenter;
	lblCreate.textAlignment = UITextAlignmentCenter;
	
	[lblAll setBackgroundColor:[UIColor darkGrayColor]];
	[lblCity setBackgroundColor:[UIColor clearColor]];
	[lblCreate setBackgroundColor:[UIColor clearColor]];
	
	lblAll.text = @"See All";
	lblCity.text = @"Select City";
	lblCreate.text = @"Create Event";
	
	
	lblAll.font = fnt;
	lblCity.font = fnt;
	lblCreate.font = fnt;
	
	lblAll.textColor = [UIColor whiteColor];	
	lblCity.textColor = [UIColor whiteColor];	
	lblCreate.textColor = [UIColor whiteColor];	
	
	lblAll.userInteractionEnabled = YES;
	lblCity.userInteractionEnabled = YES;
	lblCreate.userInteractionEnabled = YES;
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


#pragma mark UITableView Delegate mehods

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
	return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
	return 70;
}

/*- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
 {
 Album *a = [[Album alloc] initWithNibName:@"Album" bundle:[NSBundle mainBundle]];
 [self.navigationController pushViewController:a animated:YES];
 [a release];
 }*/

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	int row = indexPath.row;
	UITableViewCell *cell = [tvEvents dequeueReusableCellWithIdentifier:@"cell"];
	if (cell == nil)
	{
		cell = [[[EventsCellView alloc] initWithFrame:CGRectZero reuseIdentifier:@"cell"] autorelease];		
	}		
	return cell;
}



-(void)Back:(id)sender{
	[self.navigationController popViewControllerAnimated:YES];
}

+(void) getNav{
	[nav popNavigationItemAnimated:YES];
}



-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
	NSSet *allTouches = [event allTouches];
	
	UITouch *touch = [[allTouches allObjects] objectAtIndex:0];
	
	if (touch.view == lblCreate && currentLabel != lblCreate){
		createEventView = [[CreateEventView alloc] initWithNibName:@"CreateEventView" bundle:[NSBundle mainBundle]];
		[currentLabel setBackgroundColor:[UIColor clearColor]];
		currentLabel = lblCreate;
		[currentLabel setBackgroundColor:[UIColor darkGrayColor]];
		currentView = createEventView.view;
		
		CGRect rect = subView.frame;
		subView.hidden = TRUE;
		createEventView.view.frame = rect;
		
		[self.view addSubview:createEventView.view];
	}
	
	if (touch.view == lblAll && currentLabel!= lblAll){
		currentView.hidden = TRUE;
		currentView = subView;
		currentView.hidden = FALSE;

		[currentLabel setBackgroundColor:[UIColor clearColor]];
		currentLabel = lblAll;
		[currentLabel setBackgroundColor:[UIColor darkGrayColor]];
		
	}	
}


@end
